package interview.huawei.myself.machine_test;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str1 = in.nextLine();
        String str2 = in.nextLine();
//        String str1 = "ace";
//        String str2 = "abcde";
        int p1 = 0, p2 = 0;
        int res1 = -1, res2 = -1;
        for (int i = 0; i < str2.length(); i++) {
            if (p1 < str1.length() && str2.charAt(i) == str1.charAt(p1)) {
                p2++;
                p1++;
                res2 = i;
            }
        }
        if (p2 > 0)
            System.out.println(res2);
        else
            System.out.println(res1);
    }
}